# -"- coding: utf-8 -"-
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template

class Member(db.Model):
    name = db.StringProperty(required=True)
    when = db.DateTimeProperty(auto_now_add=True)

class MainPage(webapp.RequestHandler):
    
    def get(self):
        #self.response.headers['Content-Type'] = 'text/plain'
        #self.response.out.write('Hello, webapp World!')
        result = db.GqlQuery('SELECT * FROM Member ORDER BY when DESC')
        members = {'members': result}
        self.response.out.write(template.render('index.html', members))
        
    def post(self):
        member = Member(name = self.request.get('name'))
        
        member.put()
        
        self.redirect('/')

application = webapp.WSGIApplication([('/', MainPage)], debug=True)


def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
